package com.jdls.tanhua.template;

import com.baidu.aip.face.AipFace;
import com.jdls.tanhua.properties.AipProperties;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;

/**
 * @author 嘉德罗斯
 * @date 2021/10/23
 */
public class AipTemplate {

    @Autowired
    private AipFace aipFace;

    public boolean aip(String image){
        HashMap<String, String> options = new HashMap();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");
        // 调用接口

        String imageType = "URL";

        // 人脸检测
        JSONObject res = aipFace.detect(image, imageType, options);
        System.out.println(res.toString(2));

        Integer error_code = (Integer) res.get("error_code");
        System.out.println(error_code);
        if(error_code!=0){
            return false;
        }
        return true;
    }
}
